package com.iweb.utils;

import com.alibaba.fastjson.JSON;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class JsonUtil {

    public static void writeJsonStr(HttpServletResponse response,Object data){
        response.setCharacterEncoding("UTF-8");
        PrintWriter writer = null;
        try {
            writer = response.getWriter();
            writer.println(JSON.toJSONString(data));
            writer.flush();

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            writer.close();
        }
    }

}
